package com.atguigu.gmall.item.all.comtroller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class ItemController {

    @Autowired
    private ItemFeignClient itemFeignClient;
    //http:www.gmall.com/17.html
    //编写控制器
    @RequestMapping("{skuId}.html")
    public String getItem(@PathVariable Long skuId , Model model){
        //获取数据
        Result<Map> item = itemFeignClient.getItem(skuId);
        //存储数据
        Map data = item.getData();
        model.addAllAttributes(data);
        //返回的视图名称
        return "item/index";
    }
}
